<script setup>
import { ref } from 'vue';
import {
  Setting,
  User,
} from '@element-plus/icons-vue';

const isCollapsed = ref(false);
</script>


<template>
  <div class="sidebar-container" :class="{ collapsed: isCollapsed }">
    <el-menu
        :collapse="isCollapsed"
        default-active="2"
        class="el-menu-vertical"
        background-color="transparent"
        active-text-color="#fff"
    >
      <el-sub-menu index="1">
        <template #title>
          <el-icon class="menu-icon"><Setting /></el-icon>
          <span>系统管理</span>
        </template>
        <el-menu-item index="user">
          <el-icon class="menu-icon"><User /></el-icon>
          <span>用户管理</span>
        </el-menu-item>
      </el-sub-menu>
    </el-menu>

    <el-button
        class="toggle-button"
        @click="isCollapsed = !isCollapsed"
        :icon="isCollapsed ? 'el-icon-arrow-right' : 'el-icon-arrow-left'"
        circle
    />
  </div>
</template>

<style scoped>
.sidebar-container {
  width: 240px;
  height: 100vh;
  background: linear-gradient(145deg, #ffffff, #f8f9fa);
  box-shadow: 4px 0 16px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  position: relative;
}

.sidebar-container.collapsed {
  width: 64px;
}

.el-menu-vertical {
  border-right: none;
  flex: 1;
  padding: 16px 8px;
}

.el-menu-vertical:not(.el-menu--collapse) {
  width: 100%;
}

.el-menu-item,
.el-sub-menu__title {
  border-radius: 8px;
  margin: 4px 0;
  transition: all 0.3s ease;
}

.el-menu-item:hover,
.el-sub-menu__title:hover {
  background: rgba(91, 143, 249, 0.1) !important;
}

.el-menu-item.is-active {
  background: linear-gradient(135deg, #5b8ff9, #6c5ce7) !important;
  color: #fff !important;
  box-shadow: 0 4px 12px rgba(91, 143, 249, 0.3);
}

.menu-icon {
  margin-right: 12px;
  font-size: 18px;
  color: inherit;
}

.toggle-button {
  position: absolute;
  right: -16px;
  top: 24px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  border: none;
  transition: all 0.3s ease;
}

.toggle-button:hover {
  transform: translateX(2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* 响应式优化 */
@media (max-width: 768px) {
  .sidebar-container {
    width: 64px;
  }

  .sidebar-container:not(.collapsed) {
    width: 240px;
    z-index: 1000;
  }

  .toggle-button {
    display: none;
  }
}
</style>